<template>
  <div class="dashboard-container">
    <el-card class="welcome-card" shadow="hover">
      <div class="welcome-content">
        <div class="welcome-text">
          <h1>欢迎使用毕业论文智能查重系统</h1>
          <p class="welcome-subtitle">
            {{ userStore.isStudent ? '学生端' : '教师端' }} - {{ userStore.userName }}
          </p>
          <p class="current-time">{{ currentTime }}</p>
        </div>
        <div class="welcome-icon">
          <el-icon size="80" color="#409EFF">
            <School />
          </el-icon>
        </div>
      </div>
    </el-card>

    <!-- 快速操作区域 -->
    <div class="quick-actions">
      <h2>快速操作</h2>
      <div class="action-grid">
        <!-- 学生端快速操作 -->
        <template v-if="userStore.isStudent">
          <el-card class="action-card" shadow="hover" @click="$router.push('/student/title-check')">
            <div class="action-content">
              <el-icon size="40" color="#67C23A">
                <Document />
              </el-icon>
              <h3>题目查重</h3>
              <p>检查论文题目重复情况</p>
            </div>
          </el-card>

          <el-card class="action-card" shadow="hover" @click="$router.push('/student/paper-check')">
            <div class="action-content">
              <el-icon size="40" color="#E6A23C">
                <Files />
              </el-icon>
              <h3>论文查重</h3>
              <p>上传PDF进行内容查重</p>
            </div>
          </el-card>

          <el-card class="action-card" shadow="hover" @click="$router.push('/student/info-extraction')">
            <div class="action-content">
              <el-icon size="40" color="#409EFF">
                <DataAnalysis />
              </el-icon>
              <h3>信息提取</h3>
              <p>提取论文关键信息</p>
            </div>
          </el-card>
        </template>

        <!-- 教师端快速操作 -->
        <template v-if="userStore.isTeacher">
          <el-card class="action-card" shadow="hover" @click="$router.push('/teacher/students')">
            <div class="action-content">
              <el-icon size="40" color="#67C23A">
                <UserFilled />
              </el-icon>
              <h3>学生管理</h3>
              <p>管理学生信息和账号</p>
            </div>
          </el-card>

          <el-card class="action-card" shadow="hover" @click="$router.push('/teacher/submissions')">
            <div class="action-content">
              <el-icon size="40" color="#E6A23C">
                <DocumentCopy />
              </el-icon>
              <h3>提交记录</h3>
              <p>查看学生提交历史</p>
            </div>
          </el-card>

          <el-card class="action-card" shadow="hover" @click="$router.push('/teacher/statistics')">
            <div class="action-content">
              <el-icon size="40" color="#409EFF">
                <TrendCharts />
              </el-icon>
              <h3>统计分析</h3>
              <p>查看数据统计报告</p>
            </div>
          </el-card>
        </template>
      </div>
    </div>

    <!-- 系统信息 -->
    <el-card class="system-info-card" shadow="hover">
      <div class="system-info">
        <h3>系统信息</h3>
        <div class="info-grid">
          <div class="info-item">
            <span class="info-label">系统版本：</span>
            <span class="info-value">v1.0.0</span>
          </div>
          <div class="info-item">
            <span class="info-label">用户类型：</span>
            <span class="info-value">{{ userStore.isStudent ? '学生' : '教师' }}</span>
          </div>
          <div class="info-item" v-if="userStore.isStudent">
            <span class="info-label">专业班级：</span>
            <span class="info-value">{{ userStore.userMajor }} - {{ userStore.userClass }}</span>
          </div>
          <div class="info-item">
            <span class="info-label">学号/工号：</span>
            <span class="info-value">{{ userStore.userAccount }}</span>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { 
  School, 
  Document, 
  Files, 
  DataAnalysis, 
  UserFilled, 
  DocumentCopy, 
  TrendCharts 
} from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user'
import { useAppStore } from '@/stores/app'
import { formatDateTime } from '@/utils'

const userStore = useUserStore()
const appStore = useAppStore()

// 当前时间
const currentTime = ref('')

// 更新时间
const updateTime = () => {
  currentTime.value = formatDateTime(new Date(), 'YYYY年MM月DD日 HH:mm:ss')
}

// 定时器
let timer = null

onMounted(() => {
  appStore.setPageTitle('仪表盘')
  updateTime()
  
  // 每秒更新时间
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
.dashboard-container {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* 欢迎卡片 */
.welcome-card {
  margin-bottom: 2rem;
  border-radius: 12px;
  border: none;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
}

.welcome-text h1 {
  color: #303133;
  margin: 0 0 1rem 0;
  font-size: 2rem;
  font-weight: 600;
}

.welcome-subtitle {
  color: #409EFF;
  font-size: 1.2rem;
  margin: 0 0 0.5rem 0;
  font-weight: 500;
}

.current-time {
  color: #909399;
  margin: 0;
  font-size: 1rem;
}

.welcome-icon {
  flex-shrink: 0;
}

/* 快速操作区域 */
.quick-actions {
  margin-bottom: 2rem;
}

.quick-actions h2 {
  color: #303133;
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.action-card {
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.action-content {
  text-align: center;
  padding: 1.5rem 1rem;
}

.action-content h3 {
  color: #303133;
  margin: 1rem 0 0.5rem 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.action-content p {
  color: #909399;
  margin: 0;
  font-size: 0.9rem;
}

/* 系统信息卡片 */
.system-info-card {
  border-radius: 12px;
  border: none;
}

.system-info h3 {
  color: #303133;
  margin: 0 0 1.5rem 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.info-item {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  background: #f8f9fa;
  border-radius: 8px;
}

.info-label {
  color: #606266;
  font-weight: 500;
  margin-right: 0.5rem;
}

.info-value {
  color: #303133;
  font-weight: 600;
}

/* PC端优化设计 */
@media (max-width: 1200px) {
  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .info-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 992px) {
  .dashboard-container {
    padding: 1.5rem;
  }
  
  .welcome-text h1 {
    font-size: 2rem;
  }
}

@media (max-width: 768px) {
  .dashboard-container {
    padding: 1rem;
  }
  
  .welcome-content {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }
  
  .welcome-text h1 {
    font-size: 1.5rem;
  }
  
  .action-grid {
    grid-template-columns: 1fr;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
}
</style>